package com.example.sikong.service;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.sikong.dto.DJHangarConfigDTO;
import com.example.sikong.dto.HangarDTO;
import com.example.sikong.entity.SkDeviceConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

@Service
public class HangarService {

    @Value("${si-kong.orgSecret}")
    private String orgSecret;
    @Value("${si-kong.rtmpUrl}")
    private String rtmpUrl;
    @Value("${si-kong.video}")
    private String video;
    @Value("${si-kong.pullDomain}")
    private String pullDomain;
    @Value("${si-kong.pullKey}")
    private String pullKey;
    @Value("${si-kong.appName}")
    private String appName;

    @Autowired
    ISkDeviceConfigService skDeviceConfigService;

    public HangarDTO findByHangarSn(String sn) {
        // 属性请自行初始化
        HangarDTO hangarDTO = new HangarDTO();
        hangarDTO.setHangarSn(sn);
        DJHangarConfigDTO djHangarConfigDTO = new DJHangarConfigDTO();
        djHangarConfigDTO.setOrgSecret(orgSecret);
        djHangarConfigDTO.setRtmpUrl(rtmpUrl);
        djHangarConfigDTO.setVideo(video);
        djHangarConfigDTO.setPullDomain(pullDomain);
        djHangarConfigDTO.setPullKey(pullKey);
        djHangarConfigDTO.setActiveTime(3600*24L);
        djHangarConfigDTO.setAppName(appName);

        SkDeviceConfig skDeviceConfig = new SkDeviceConfig();
        skDeviceConfig.setSn(sn);
        SkDeviceConfig one = skDeviceConfigService.getOne(new QueryWrapper<>(skDeviceConfig));
        if (one != null) {
            djHangarConfigDTO.setCamera(one.getCamera());
        }
        hangarDTO.setConfig(JSON.parseObject(JSON.toJSONString(djHangarConfigDTO)).getInnerMap());
        return hangarDTO;
    }
}
